import { myEnv } from '@/myEnv';
import { mergeRequest } from '@/utils';

type LoginForm = {
    phoneNumber: string;
    code: string;
};
/** 提交短信验证码验证登录 */
export const apiGetUserLogin = async (loginForm: LoginForm) => {
    const response: MyResponse<any> = await sendRequest(loginForm);
    return response;
};

const sendRequest = async (loginForm: LoginForm) => {
    let response: MyResponse<any>;
    if (myEnv.IS_ON_LINE) {
        response = await mergeRequest({
            url: `login/check`,
            method: 'POST',
            data: {
                smsVerifyCode: loginForm.code,
                userPhoneNumber: loginForm.phoneNumber,
            },
        });
    } else {
        response = {
            code: '200',
            message: 'ok',
            data: {},
        };
    }
    return response;
};
